using System;
using System.Collections.Generic;
using System.Text;

namespace Woz
{
    /// <summary>
    /// changes the name of a screen thumbnail
    /// </summary>
    internal class RenameScreenThumbnailAction : Woz.Action
    {
        /// <summary>
        /// default constructor
        /// </summary>
        /// <param name="pScreenThumbnail">the screen thumbnail to rename</param>
        /// <param name="pNewName">the new name</param>
        public RenameScreenThumbnailAction(Woz.ScreenThumbnail pScreenThumbnail, string pNewName)
        {
            // save the current screen
            this.mScreen = pScreenThumbnail.Screen;

            // save the screen thumbnail
            this.mScreenThumbnail = pScreenThumbnail;

            // save the new name
            this.mNewName = pNewName;

            // save the old name
            this.mOldName = this.mScreen.Name;
        }

        /// <summary>
        /// gets the name of the tool this action belongs to none in this case
        /// </summary>
        public override string ToolName
        {
            get
            {
                return "";
            }
        }

        /// <summary>
        /// gets whether this action can be propagated or not
        /// </summary>
        public override bool Propagatable
        {
            get
            {
                return false;
            }
        }

        /// <summary>
        /// changes the name of this screen thumbnail to the new name
        /// </summary>
        /// <param name="pScreen">not used for non propagateable action</param>
        protected override void OnExecute(Woz.Screen pScreen)
        {
            // rename the screen thumbnail with the new name
            this.mScreenThumbnail.Screen.Name = this.mNewName;
        }

        /// <summary>
        /// changes the name of this screen thumbnail back to its old name
        /// </summary>
        /// <param name="pScreen">not used for non propagateable action</param>
        protected override void OnUnExecute(Woz.Screen pScreen)
        {
            // rename the screen thumbnail with the old name
            this.mScreenThumbnail.Screen.Name = this.mOldName;
        }

        /// <summary>
        /// the new name of the screen thumbnail
        /// </summary>
        private string mNewName;

        /// <summary>
        /// the old name of the screen thumbnail
        /// </summary>
        private string mOldName;

        /// <summary>
        /// the screen thumbnail this renaming applies to
        /// </summary>
        private Woz.ScreenThumbnail mScreenThumbnail;
    }
}
